package com.chinags.system.report.controller;

import java.util.List;

import com.chinags.common.core.domain.Ztree;
import com.chinags.common.utils.StringUtils;
import com.chinags.framework.util.ShiroUtils;
import com.chinags.system.domain.SysDept;
import com.chinags.system.report.domain.TJcFlzddwCount;
import com.chinags.system.report.service.ITJcFlzddwCountService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.chinags.common.annotation.Log;
import com.chinags.common.enums.BusinessType;
import com.chinags.common.core.controller.BaseController;
import com.chinags.common.core.page.TableDataInfo;
import com.chinags.common.core.domain.AjaxResult;
import com.chinags.common.utils.poi.ExcelUtil;

/**
 * 省市区 信息操作处理
 * 
 * @author shichenxing
 * @date 2019-06-22
 */
@Controller
@RequestMapping("/system/tJcFlzddwCount")
public class TJcFlzddwCountController extends BaseController
{
    private String prefix = "system/tJcFlzddwCount";
    private String prefix1 = "system/report/tJcFlzddw";
	
	@Autowired
	private ITJcFlzddwCountService tJcFlzddwCountService;
	
	@RequiresPermissions("system:tJcFlzddwCount:view")
	@GetMapping()
	public String tJcFlzddwCount()
	{
	    return prefix + "/tJcFlzddwCount";
	}
	
	/**
	 * 查询省市区列表
	 */
	@RequiresPermissions("system:tJcFlzddwCount:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TJcFlzddwCount tJcFlzddwCount)
	{
		startPage();
        List<TJcFlzddwCount> list = tJcFlzddwCountService.selectTJcFlzddwCountList(tJcFlzddwCount);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出省市区列表
	 */
	@RequiresPermissions("system:tJcFlzddwCount:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TJcFlzddwCount tJcFlzddwCount)
    {
    	List<TJcFlzddwCount> list = tJcFlzddwCountService.selectTJcFlzddwCountList(tJcFlzddwCount);
        ExcelUtil<TJcFlzddwCount> util = new ExcelUtil<TJcFlzddwCount>(TJcFlzddwCount.class);
        return util.exportExcel(list, "tJcFlzddwCount");
    }
	
	/**
	 * 新增省市区
	 */
	@GetMapping("/add/{createId}")
	public String add(@PathVariable("createId") Long parentId, ModelMap mmap)
	{
		mmap.put("dept", tJcFlzddwCountService.selectDeptById(parentId));
		return prefix + "/add";
	}
	/**
	 * 新增保存省市区
	 */
	@RequiresPermissions("system:tJcFlzddwCount:add")
	@Log(title = "省市区", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TJcFlzddwCount tJcFlzddwCount)
	{		
		return toAjax(tJcFlzddwCountService.insertTJcFlzddwCount(tJcFlzddwCount));
	}

	/**
	 * 修改省市区
	 */
	@GetMapping("/edit/{createId}")
	public String edit(@PathVariable("createId") Long createId, ModelMap mmap)
	{
		TJcFlzddwCount dept =  tJcFlzddwCountService.selectDeptById(createId);
		if (StringUtils.isNotNull(dept) && 100L == createId)
		{
			dept.setParentName("无");
		}
		mmap.put("dept", dept);
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存省市区
	 */
	@RequiresPermissions("system:tJcFlzddwCount:edit")
	@Log(title = "省市区", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TJcFlzddwCount tJcFlzddwCount)
	{
		return toAjax(tJcFlzddwCountService.updateTJcFlzddwCount(tJcFlzddwCount));
	}
	
	/**
	 * 删除省市区
	 */
	@RequiresPermissions("system:tJcFlzddwCount:remove")
	@Log(title = "省市区", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tJcFlzddwCountService.deleteTJcFlzddwCountByIds(ids));
	}

	@GetMapping("/treeData")
	@ResponseBody
	public List<Ztree> treeData()
	{
		List<Ztree> ztrees = tJcFlzddwCountService.selecitDeptTree(new TJcFlzddwCount());
		return ztrees;
	}
	/**
	 * 选择部门树
	 */
	@GetMapping("/selectDeptTree/{createId}")
	public String selectDeptTree(@PathVariable("createId") Long createId, ModelMap mmap)
	{
		mmap.put("dept", tJcFlzddwCountService.selectDeptById(createId));
		return prefix1 + "/tree";
	}
	/**
	 * 校验部门名称
	 */
	@PostMapping("/checkDeptNameUnique")
	@ResponseBody
	public String checkDeptNameUnique(TJcFlzddwCount dept)
	{
		return tJcFlzddwCountService.checkDeptNameUnique(dept);
	}
/*	*//**
	 * 保存
	 *//*
	@Log(title = "部门管理", businessType = BusinessType.UPDATE)
	@RequiresPermissions("system:dept:edit")
	@PostMapping("/edit")
	@ResponseBody

	public AjaxResult editSave(TJcFlzddwCount dept)
	{
		dept.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(tJcFlzddwCountService.updateDept(dept));
	}*/
	
}
